package com.study.springcloud.serivce.fallback;

import com.study.springcloud.consts.Constant;
import com.study.springcloud.response.ResultObject;
import com.study.springcloud.serivce.GoodsRemoteClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Author Chen Jie
 * @Date 2022/3/18 20:47
 * @Version 1.0
 */
@Slf4j
//需要注入到容器, 泛型为Feign的接口类
@Component
public class GoodsRemoteClientFallbackFactory implements FallbackFactory<GoodsRemoteClient> {
    @Override
    public GoodsRemoteClient create(Throwable throwable) {
        return new GoodsRemoteClient() {
            @Override
            public ResultObject goods() {
                log.info(throwable.getMessage());
                return new ResultObject(Constant.ERROR, "feign服务调用降级...GoodsRemoteClientFallbackFactory", null);
            }
        };
    }
}
